package org.dromara.common.core.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class DateListSort {
    //String -> Date
    public static Date stringToDate(String dateStr) {
        Date date = null;
        try {
            SimpleDateFormat ft = new SimpleDateFormat("yyyyMMdd");
            date = ft.parse(dateStr);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    //Date -> String
    public static String dateToString(Date date) {
        SimpleDateFormat ft = new SimpleDateFormat("yyyyMMdd");
        return ft.format(date);
    }


    public static void testSort(List<Date> list) {
        for (int i = 0; i < list.size() - 1; i++) {
            for (int j = 1; j < list.size() - i; j++) {
                if (list.get(i).before(list.get(i + j))) {
                    Date empty;
                    empty = list.get(i);
                    list.set(i, list.get(i + j));
                    list.set(i + j, empty);
                }
            }
        }
    }
}
